export function renderMixin(Vue) {
  Vue.prototype._c = function () {
    //标签
    return createELmement(this, ...arguments);
  };
  Vue.prototype._v = function (text) {
    //文本
    return createText(text);
  };
  Vue.prototype._s = function (val) {
    //变量
    return val === null
      ? ""
      : typeof val === "object"
      ? JSON.stringify(val)
      : val;
  };
  Vue.prototype._render = function () {
    let vm = this;
    let render = vm.$options.render;
    let vnode = render.call(this);
    return vnode;
  };
}
//创建元素
function createELmement(vm, tag, data = {}, ...children) {
  //判断是组件还是标签
  if (isResced(tag)) {
    return vnode(vm, tag, data, data.key, children);
  } else {
    //组件 
    const Ctor = vm.$options["components"][tag]; //取出对应的组件标签的方法实列
    // vuecomponent(opts) {
    //初始化
    //   this._init(opts);
    // }                        
    return Createcomponents(vm, tag, data, children, Ctor); //子组件的虚拟dom
  }
}
function isResced(tag) {
  return ["a", "div", "h", "button", "span", "input", "p", "img"].includes(tag);
}
//创建组件的虚拟dom
function Createcomponents(vm, tag, data, children, Ctor) {
  if (typeof Ctor === "object") {//自己组件的时候走这个方法生成实列
    Ctor = vm.constructor.extend(Ctor);
  }
  //组件初始化
  data.hook = {
    //初始化子组件 创建实列
    init(vnode) {
      let child = (vnode.componentInstance = new vnode.compontOptions.Ctor({})); //new 一个子类的实列对象 new Sub()
      child.$mount(); //组件的挂载 不传参数就挂载在el上 
    },
  };
  return vnode(
    vm,
    "vue-componet" + "-" + tag,
    data,
    undefined,
    undefined,
    undefined,
    { Ctor, children }
  );
}
//创建文本
function createText(text) {
  return vnode(undefined, undefined, undefined, undefined, undefined, text);
}
//创建vnode
function vnode(vm, tag, data, key, children, text, compontOptions) {
  return { vm, tag, data, key, children, text, compontOptions };
}
